#ifndef GLOBAL_H
#define GLOBAL_H

#include "config.h"

#ifndef _TYPE_DEFINED
#define _TYPE_DEFINED

#ifndef   bit
  #define bit  unsigned char
#endif
#ifndef   uchar
  #define uchar  unsigned char
#endif
#ifndef   ushort
  #define ushort unsigned short
#endif
#ifndef   ulong
  #define ulong unsigned long
#endif
#ifndef   uint
  #define uint unsigned long
#endif


#ifndef   u8
  #define u8  unsigned char
  #define U8  unsigned char
#endif
#ifndef   u16
  #define u16 unsigned short
  #define U16 unsigned short
#endif
#ifndef   u32
  #define u32 unsigned long
  #define U32 unsigned long
#endif

#endif// _TYPE_DEFINED

#define UNUSED(x)               ((x)=(x))
#ifndef _STR
#define __STR(x)                #x
#define _STR(x)                 __STR(x)
#endif

//------------------------------------------------------------------------------
// 常量定义
//------------------------------------------------------------------------------

// 系统频率
#define SYSCLK                          INTCLK

#define UNUSED(x)       ((x)=(x))

#define max(a, b)       ((a) > (b) ? (a) : (b))
#define min(a, b)       ((a) < (b) ? (a) : (b))

//------------------------------------------------------------------------------
// 数据类型
//------------------------------------------------------------------------------

#define MSB             1
#define LSB             0

typedef union tagUU16
{
    U8  UU8[2];
    U16 UU16;
} UU16;

// 读文件请求
typedef struct FILE_REQUEST
{
    uchar fid;      // 文件号
    uchar len;      // 读取长度
    ushort addr;    // 记录地址
} FILE_REQUEST;

typedef struct FILE_DESC
{
    ushort mask;
    ushort count;
    union
    {
        ushort *w;
        float *f;
    } ptr;
} FILE_DESC;

__packed typedef struct RECT
{
    long x0;
    long y0;
    long x1;
    long y1;
} RECT;

enum ACCEL_MODE{
    LOW_ACCELERRATE = 0,
    MID_ACCELERRATE,
    HIGH_ACCELERRATE,
    ACCELERRATE_COUNT,
};

typedef struct FREQ_HEAD
{
    ushort *freq_table;
    ushort speed_tatble_size;
    ushort accel;
} FREQ_HEAD;
#endif // GLOBAL_H
